﻿using JE.MicroMVVM.Example.Common;
using JE.MicroMVVM.Example.Views;
using MicroMVVM;
using MicroMVVM.Helpers;
using MicroMVVM.Interfaces;
using MicroMVVM.Navigation;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;

namespace JE.MicroMVVM.Example.ViewModels
{
    public class TestOneViewModel : BindableBase, INavigation, IDesigntimeAware
    {
        private const string BlueVisualState = "Blue";
        private const string RedVisualState = "Red";

        private readonly IVisualStateManager _visualStateManager;

        private bool _isRed;

        private string _test1;
        private string _test2;

        public string Test1
        {
            get { return _test1; }
            set { SetProperty(ref _test1 , value); }
        }

        public string Test2
        {
            get { return _test2; }
            set { SetProperty(ref _test2, value); }
        }

        public ICommand NavigateCommand { get; set; }

        public ICommand VisualStateCommand { get; set; }

        public Frame Current { get; set; }

        public TestOneViewModel(IVisualStateManager visualStateManager)
        {
            _visualStateManager = visualStateManager;

            _isRed = true;

            Test1 = "Test 1 string";
            Test2 = "Test 2 string";

            NavigateCommand = new DelegateCommand(OnNavigateCommand);
            VisualStateCommand = new DelegateCommand(OnVisualStateCommand);
        }

        private void OnVisualStateCommand(object obj)
        {
            var visualState = _isRed ? BlueVisualState : RedVisualState;

            _isRed = !_isRed;

            _visualStateManager.GoToVisualState(visualState);
        }

        private void OnNavigateCommand(object obj)
        {
            this.Navigate(typeof (SecondPage));
        }

        public void DesigntimeAware()
        {
        }

        public void OnNavigating()
        {
            var s = string.Empty;
        }

        public void OnNavigated(object parameter)
        {
            var s = string.Empty;
        }
    }
}